package com.turbo.cloud.ums.web.webservice;

import com.turbo.cloud.core.api.R;
import com.turbo.cloud.core.api.Result;
import com.turbo.cloud.core.validated.*;
import com.turbo.cloud.ums.utils.vuemenu.VueMenu;
import com.turbo.cloud.ums.web.logic.MenuLogic;
import com.turbo.cloud.ums.web.model.menu.UmsMenuQo;
import com.turbo.cloud.ums.web.model.menu.UmsMenuDo;
import com.turbo.cloud.ums.web.model.menu.UmsMenuVo;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色菜单表 前端控制器
 * </p>
 *
 * @author zhangluning
 * @since 2022-10-11
 */
@RequiredArgsConstructor
@RestController
public class UmsMenuController {
    final MenuLogic menuLogic;

    /**
     * 查询菜单树列表
     *
     * @return TreeList
     */
    @PostMapping(name = "查询菜单树列表", value = "/webservice/menu/queryMenuTreeList")
    public Result<List<UmsMenuVo>> queryMenuTreeList() {
        List<UmsMenuVo> result = menuLogic.queryMenuTreeList();
        return R.result(result);
    }

    /**
     * 查询菜单树列表，并根据权限ID标记选中
     *
     * @return TreeList
     */
    @PostMapping(name = "查询菜单树列表，并根据权限ID标记选中", value = "/webservice/menu/queryMenuCheckedTreeListOfPermissionId")
    public Result<List<UmsMenuVo>> queryMenuCheckedTreeListOfPermissionId(@RequestBody UmsMenuQo umsMenuQo) {
        List<UmsMenuVo> result = menuLogic.queryMenuCheckedTreeListOfPermissionId(umsMenuQo);
        return R.result(result);
    }

    /**
     * 根据权限ID，查询菜单树列表
     *
     * @return
     */
    @PostMapping(name = "根据权限ID，查询菜单树列表", value = "/webservice/menu/queryCheckedMenuTreeListByPermissionId")
    public Result<List<UmsMenuVo>> queryCheckedMenuTreeListByPermissionId(@RequestBody @Validated(SelectWhereValidated.class) UmsMenuQo umsMenuQo) {
        List<UmsMenuVo> result = menuLogic.queryCheckedMenuTreeListByPermissionId(umsMenuQo);
        return R.result(result);
    }

    /**
     * 查询登录人的菜单树列表
     *
     * @return
     */
    @GetMapping(name = "查询登录人的菜单树列表", value = "/webservice/menu/queryMenuTreeByCurrentUser")
    public Result<List<UmsMenuVo>> queryMenuTreeByCurrentUser() {
        List<UmsMenuVo> result = menuLogic.queryMenuTreeByCurrentUser();
        return R.result(result);
    }

    /**
     * 查询登录人的菜单Vue格式树列表
     *
     * @return
     */
    @GetMapping(name = "查询登录人的菜单Vue格式树列表", value = "/webservice/menu/queryVueMenuTreeByCurrentUser")
    public Result<List<VueMenu>> queryVueMenuTreeByCurrentUser() {
        List<VueMenu> result = menuLogic.queryVueMenuTreeByCurrentUser();
        return R.result(result);
    }

    /**
     * 查询登录人的菜单Vue格式简单列表
     *
     * @return
     */
    @GetMapping(name = "查询登录人的菜单Vue格式简单列表", value = "/webservice/menu/queryVueMenuListByCurrentUser")
    public Result<List<VueMenu>> queryVueMenuListByCurrentUser() {
        List<VueMenu> result = menuLogic.queryVueMenuListByCurrentUser();
        return R.result(result);
    }

    /**
     * 查询登录人的菜单列表
     *
     * @return
     */
    @GetMapping(name = "查询登录人的菜单列表", value = "/webservice/menu/queryMenuListByCurrentUser")
    public Result<List<UmsMenuVo>> queryMenuListByCurrentUser() {
        List<UmsMenuVo> result = menuLogic.queryMenuListByCurrentUser();
        return R.result(result);
    }

    /**
     * 获取单个菜单
     *
     * @param id 菜单ID
     * @return
     */
    @GetMapping(name = "获取单个菜单", value = "/webservice/menu/queryMenuById")
    public Result<UmsMenuVo> queryMenuById(@Validated @NotBlank(message = "菜单ID不能为空") String id) {
        UmsMenuVo result = menuLogic.queryMenuById(id);
        return R.result(result);
    }

    /**
     * 新增菜单
     *
     * @param umsMenuDo 实体
     * @return
     */
    @PostMapping(name = "新增菜单", value = "/webservice/menu/createMenu")
    public Result<Boolean> createMenu(@RequestBody @Validated(InsertValidated.class) UmsMenuDo umsMenuDo) {
        boolean result = menuLogic.createMenu(umsMenuDo);
        return R.result(result);
    }

    /**
     * 修改菜单
     *
     * @param umsMenuDo 实体
     * @return
     */
    @PostMapping(name = "修改菜单", value = "/webservice/menu/modifyMenu")
    public Result<Boolean> modifyMenu(@RequestBody @Validated(UpdateValidated.class) UmsMenuDo umsMenuDo) {
        boolean result = menuLogic.modifyMenu(umsMenuDo);
        return R.result(result);
    }

    /**
     * 开启、关闭菜单有效状态
     *
     * @param id 菜单ID
     * @return Boolean
     */
    @GetMapping(name = "开启、关闭菜单有效状态", value = "/webservice/menu/enabledMenuStateById")
    public Result<Boolean> enabledPermissionStateById(@RequestParam @NotBlank(message = "菜单ID不能为空") String id) {
        boolean result = menuLogic.enabledMenuStateById(id);
        return R.result(result);
    }

    /**
     * 删除菜单
     *
     * @param id 菜单ID
     * @return
     */
    @GetMapping(name = "删除菜单", value = "/webservice/menu/removeMenuById")
    public Result<Boolean> removeMenuById(@NotBlank(message = "菜单ID不能为空") String id) {
        boolean result = menuLogic.removeMenuById(id);
        return R.result(result);
    }
}
